/* eslint valid-jsdoc: "off" */

'use strict';
const fs = require('fs');
//node.js 路径操作对象
const path = require('path');
const os = require('os');
//获取本机ip
function getIpAddress() {
  /**os.networkInterfaces() 返回一个对象，该对象包含已分配了网络地址的网络接口 */
  var interfaces = os.networkInterfaces();
  // console.log(interfaces);
  for (var devName in interfaces) {
    var iface = interfaces[devName];
    for (var i = 0; i < iface.length; i++) {
      var alias = iface[i];
      if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
        return alias.address;
      }
    }
  }
}
const myHost = getIpAddress();
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {
    security: {
      csrf: {
        enable: false,
        useSession: false,
        // cookieName: "csrfToken",

      },
    },
    cors: {
      // origin:ctx=>ctx.get("Origin"),
      origin: "*",
      credentials: true,
      allowMethods: "GET,POST,PUT,HEAD,PATCH,OPTIONS"
    }
  };

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1603182970034_5337';

  // add your middleware config here
  config.middleware = ['errorHandler'];
  config.secret = 'killbill'
  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  const whitelist = [
    // images
    '.jpg', '.jpeg', // image/jpeg
    '.png', // image/png, image/x-png
    '.gif', // image/gif
    '.bmp', // image/bmp
    '.wbmp', // image/vnd.wap.wbmp
    '.webp',
    '.tif',
    '.psd',
    // text
    '.lock',
    '.xlsx',
    '.docx',
    '.svg',
    '.txt',
    '.*',
    '.js', '.jsx',
    '.json',
    '.css', '.less',
    '.html', '.htm',
    '.xml',
    '.pdf',
    // tar
    '.zip',
    '.gz', '.tgz', '.gzip', '.rar', '.7z',
    // video
    '.webm',
    '.mp3',
    '.mp4',
    '.avi',
    // 
    '.exe','.apk','.'
  ];
  config.multipart = {
    fileSize: '5000mb',
    mode: 'stream',
    whitelist,
    fileExtensions: ['.xls', '.txt'], // 扩展几种上传的文件格式
  };

  // config.view = {
  //   root: path.join(appInfo.baseDir, 'app/public'),
  // }
  config.static = {
    // 静态化访问前缀,如：`http://127.0.0.1:7001/static/images/logo.png`
    prefix: '/file/',
    dir: path.join(appInfo.baseDir, 'app/file/'), // `String` or `Array:[dir1, dir2, ...]` 静态化目录,可以设置多个静态化目录
    dynamic: true, // 如果当前访问的静态资源没有缓存，则缓存静态文件，和`preload`配合使用；
    preload: false,
    maxAge: 31536000, // in prod env, 0 in other envs
    buffer: true, // in prod env, false in other envs
  };

  config.api = "http://www.mxnzp.com/api/";
  config.mysql = {
    client: {
      // host
      host: 'localhost',
      // 端口号
      port: '3306',
      // 用户名
      user: 'root',
      // 密码
      password: 'root',
      // 数据库名
      database: 'egg_test',
    },
    // 是否加载到 app 上，默认开启
    app: true,
    // 是否加载到 agent 上，默认关闭
    agent: false,
    debug: true,
  };
  return {
    ...config,
    ...userConfig,
  };
};